package com.lib76.socket.model.protocol;

import java.util.List;

import com.lib76.socket.Constants;

public class SocketProtocolObject{
	
	public final static String PROTOCOL_REQUEST = "request";
	public final static String PROTOCOL_RESPONSE = "response";
	
	private String direction = PROTOCOL_REQUEST;
	private String version;
	private String type;
	private List<SocketProtocolParameter> headerProtocolParameter;
	private SocketProtocol protocol;
	private Integer headerLength;
	
	public String getDirection() {
		return direction;
	}

	public void setDirection(String direction) {
		this.direction = direction;
	}

	public SocketProtocol getProtocol() {
		return protocol;
	}
	
	public void setProtocol(SocketProtocol protocol) {
		this.protocol = protocol;
	}
	
	public int getBodyLength(){
		if(PROTOCOL_REQUEST.equals(direction)){
			return protocol.requestBodyLength();
		}else if(PROTOCOL_RESPONSE.equals(direction)){
			return protocol.responseBodyLength();
		}
		return 0;
	}
	
	public Integer getHeaderLength() {
		return headerLength;
	}
	
	public void setHeaderLength(Integer headerLength) {
		this.headerLength = headerLength;
	}
	
	public String getVersion() {
		return version;
	}
	
	public void setVersion(String version) {
		this.version = version;
	}
	
	/**
	 * ��ȡ��Ϣ������
	 * @return
	 */
	public String getCommand(){
		if(PROTOCOL_REQUEST.equals(direction)){
			return protocol.getRequestCommand();
		}else if(PROTOCOL_RESPONSE.equals(direction)){
			return protocol.getResponseCommand();
		}
		return null;
	}
	
	public List<SocketProtocolParameter> getHeaderProtocolParameter() {
		return headerProtocolParameter;
	}
	
	public void setHeaderProtocolParameter(
			List<SocketProtocolParameter> headerProtocolParameter) {
		this.headerProtocolParameter = headerProtocolParameter;
	}
	
	public List<SocketProtocolParameter> getBodyFields(){
		if(PROTOCOL_REQUEST.equals(direction)){
			return protocol.getRequestParameters();
		}else if(PROTOCOL_RESPONSE.equals(direction)){
			return protocol.getResponseParameters();
		}
		return null;
	}
	
	/**
	 * ��ȡ�������ʽ:byte,string,json
	 * @return
	 */
	public String getBodyType(){
		if(PROTOCOL_REQUEST.equals(direction)){
			return protocol.getRequestType();
		}else if(PROTOCOL_RESPONSE.equals(direction)){
			return protocol.getResponseType();
		}
		return null;
	}
	
	public boolean isRequest(){
		if(Constants.MSG_PROTOCOL_DIRECTION_REQUEST.equals(direction)){
			return true;
		}
		return false;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}
	
}